package com.lmh.graphdisease.utils;

import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @author lmh
 * @desc 数据返回回答类，包括处理查询的数据转化、分析、处理(接收数据为从neo4j数据库中查询的数据)
 * @date 2023/3/18
 */
public class AnswerUtil {


    /**
     *@author lmh
     *@date 2023/3/26
     *@desc 回复模板
     * 参数是 问题类型questionType 数据库查询出的数据sqlAnswer（封装在map里）
     */
    public static String getAnswer(String questionType, Map<String,List<String>> sqlAnswer){
        StringBuilder resultAnswer = new StringBuilder();

        if(sqlAnswer == null || sqlAnswer.isEmpty()) {
            return resultAnswer.toString();
        }
        //随机数生成，可更换模板
        int number = new Random().nextInt(10) + 1;
        String str = "";
        if(questionType == "disease_symptom"){
            //暂时只处理一种疾病吧
//            if(sqlAnswer.get("disease_name").size()>1){
//                List<String> diseases = sqlAnswer.get("disease_name"){
//
//                }
//            }else {

//            }
            if(number > 5){
                resultAnswer.append(getListString(sqlAnswer.get("disease_name"))+"的症状包括："+ getListString(sqlAnswer.get("disease_symptom")));
            }else {
                resultAnswer.append(getListString(sqlAnswer.get("disease_name"))+"通常有以下症状："+ getListString(sqlAnswer.get("disease_symptom")));
            }

        }else if(questionType == "disease_cause"){
            if(number > 5){
                str = "可能的成因有：";
            }else {
                str = "的出现，可能是因为：";
            }
            resultAnswer.append(getListString(sqlAnswer.get("disease_name"))+str+sqlAnswer.get("disease_cause"));

        }else if(questionType == "disease_prevent"){

            if(number > 5){
                str = "的预防措施有如下几种：";
            }else {
                str = "可以通过以下方式预防：";
            }
            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_prevent")));

        }else if(questionType == "disease_check"){
            if(number > 5){
                str = "需要检查的项目有：";
            }else {
                str = "需要去检查：";
            }
            resultAnswer.append("患有" + getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_check")));
        }else if(questionType == "disease_lasttime"){

            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + "治疗可能持续的时间大概为：" + getListString(sqlAnswer.get("disease_lasttime")));

        }else if(questionType == "disease_cureway"){

            if(number > 5){
                str = "通常有以下治疗方式：";
            }else {
                str = "可以通过如下方式进行治疗：";
            }
            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_cureway")));

        }else if(questionType == "disease_cureprob"){

            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + "参考治愈概率为(仅供参考)：" + getListString(sqlAnswer.get("disease_cureprob")));

        }else if(questionType == "disease_easyget"){

            if(number > 5){
                str = "需要注意的人群有：";
            }else {
                str = "的易感人群为：";
            }
            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_easyget")));

        }else if(questionType == "disease_desc"){

            if(number > 5){
                str = "简单介绍一下：";
            }else {
                str = "是什么疾病呢？";
            }
            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_desc")));

        }else if(questionType == "disease_acompany"){
            if(number > 5){
                str = "这种疾病的并发症有：";
            }else {
                str = "有如下并发症，需要注意：";
            }
            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_acompany")));

        }else if(questionType == "disease_drug"){
            if(number > 5){
                str = "需要的药品有：";
            }else {
                str = "通常使用的药品有：";
            }
            resultAnswer.append("患有" + getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_drug")));
        }else if(questionType == "symptom_disease"){
            if(number > 5){
                str = "症状基础上，可能染上的疾病有：";
            }else {
                str = "这些症状出现，可能的疾病有";
            }
            resultAnswer.append("出现"+getListString(sqlAnswer.get("symptom_name")) + str + getListString(sqlAnswer.get("symptom_disease")));

        }else if(questionType == "drug_disease"){
            if(number > 5){
                str = "能缓解、治愈的疾病有：";
            }else {
                str = "可以缓解：";
            }
            resultAnswer.append(getListString(sqlAnswer.get("drug_name")) + str + getListString(sqlAnswer.get("drug_disease")));
        }else if(questionType == "check_disease"){
            if(number > 5){
                str = "可以查出以下疾病：";
            }else {
                str = "能查出：";
            }
            resultAnswer.append("经过" + getListString(sqlAnswer.get("check_name")) + str + getListString(sqlAnswer.get("check_disease")));
        }else if(questionType == "disease_not_food"){
            if(number > 5){
                str = "的患者不能吃：";
            }else {
                str = "的话，不可以吃：";
            }
            resultAnswer.append("患有"+getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_not_food")));
        }else if(questionType == "disease_do_food"){
            if(number > 5){
                str = "患者，最好吃些：";
            }else {
                str = "的人要吃：";
            }
            resultAnswer.append(getListString(sqlAnswer.get("disease_name")) + str + getListString(sqlAnswer.get("disease_do_food")));
        }else if(questionType == "food_not_disease"){
            if(number > 5){
                str = "的疾病有：";
            }else {
                str = "的病症有：";
            }
            resultAnswer.append("不能吃" + getListString(sqlAnswer.get("food_name")) + str + getListString(sqlAnswer.get("food_not_disease")));
        }else if(questionType == "food_do_disease"){
            if(number > 5){
                str = "的疾病有";
            }else {
                str = "的病症有：";
            }
            resultAnswer.append("能吃" + getListString(sqlAnswer.get("food_name")) + str + getListString(sqlAnswer.get("food_do_disease")));
        }
        return resultAnswer.toString();
    }

    /**
     *@author lmh
     *@date 2023/3/26
     *@desc list toString方法的通俗版
     */
    public static String getListString(List<String> lists){
        StringBuilder stringBuilder = new StringBuilder();
        if(lists == null) return "";
        for (String str:lists){
            if(stringBuilder.isEmpty() || stringBuilder == null){
                stringBuilder.append(str);
            }else {
                stringBuilder.append(" " + str);
            }
        }
        return stringBuilder.toString();
    }


}
